﻿using System;
using System.Windows.Forms;

namespace NExplorer.Controls
{
	internal class ExplorerToolBar : ToolStrip, IMainToolBar
	{
		public event EventHandler<EventArgs<ExplorerToolBarButton>> ButtonWithShortcutKeysAdded;
		public event EventHandler<EventArgs<ExplorerToolBarButton>> ButtonWithShortcutKeysRemoved;

		public IToolBarButton AddButton(ICommand command)
		{
			return AddButton(command, Keys.None);
		}

		public IToolBarButton AddButton(ICommand command, Keys shortcut)
		{
			ExplorerToolBarButton button = new ExplorerToolBarButton(command, shortcut);
			Items.Add(button);

			if (shortcut != Keys.None && ButtonWithShortcutKeysAdded != null)
			{
				ButtonWithShortcutKeysAdded(this, new EventArgs<ExplorerToolBarButton>(button));
			}

			return button;
		}

		public void RemoveButton(IToolBarButton button)
		{
			ExplorerToolBarButton item = button as ExplorerToolBarButton;

			if (item != null)
			{
				Items.Remove(item);

				if (item.Keys != Keys.None && ButtonWithShortcutKeysRemoved != null)
				{
					ButtonWithShortcutKeysRemoved(this, new EventArgs<ExplorerToolBarButton>(item));		
				}
			}
		}
	}
}
